home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE23
/
PASTOWEB
/
PasToWebForm.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-05-09
|
3KB
|
122 lines
unit PasToWebForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TForm1 = class (TForm)
EditSource: TEdit;
BtnHTML: TButton;
EditCopyr: TEdit;
BtnInput: TButton;
OpenDialog1: TOpenDialog;
EditDest: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
BtnOpen: TButton;
BtnInfo: TButton;
procedure BtnHTMLClick(Sender: TObject);
procedure BtnInputClick(Sender: TObject);
procedure EditDestChange(Sender: TObject);
procedure BtnOpenClick(Sender: TObject);
procedure BtnInfoClick(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
Convert, ShellApi;
procedure TForm1.BtnHTMLClick(Sender: TObject);
var
Source, BinSource, Dest: TStream;
Parser: THtmlParser;
begin
// extract the target file name
if FileExists (EditDest.Text) then
if MessageDlg ('Overwrite the existing file ' + EditDest.Text + '?',
mtConfirmation, [mbYes, mbNo], 0) = idNo then
Exit;
// create the two streams
Dest := TFileStream.Create (EditDest.Text,
fmCreate or fmOpenWrite);
if ExtractFileExt(EditSource.Text) = '.dfm' then
begin
// convert the DFM file to text
BinSource := TFileStream.Create (EditSource.Text, fmOpenRead);
Source := TMemoryStream.Create;
ObjectResourceToText (BinSource, Source);
Source.Position := 0;
end
else
begin
Source := TFileStream.Create (EditSource.Text, fmOpenRead);
BinSource := nil;
end;
// parse the source code
try
Parser := THtmlParser.Create (Source, Dest);
try
Parser.Alone := True;
Parser.Filename := EditSource.Text;
Parser.Copyright := EditCopyr.Text;
if ExtractFileExt(EditSource.Text) = '.dfm' then
Parser.SetKeywordType (ktDfm);
Parser.Convert;
finally
Parser.Free;
end;
finally
Dest.Free;
Source.Free;
BinSource.Free;
end;
// enable the third button
BtnOpen.Enabled := True;
end;
procedure TForm1.BtnInputClick(Sender: TObject);
begin
with OpenDialog1 do
if Execute then
begin
EditSource.Text := Filename;
EditDest.Text := ChangeFileExt(FileName, '_' +
Copy (ExtractFileExt(Filename), 2, 3)) + '.HTM';
BtnHtml.Enabled := True;
end;
end;
procedure TForm1.EditDestChange(Sender: TObject);
begin
BtnOpen.Enabled := False;
end;
procedure TForm1.BtnOpenClick(Sender: TObject);
begin
ShellExecute (Handle, 'open',
PChar (EditDest.Text), '', '', sw_ShowNormal);
end;
procedure TForm1.BtnInfoClick(Sender: TObject);
begin
// this isn't true any more
MessageDlg (Caption + #13#13 +
'Web: http://ourworld.compuserve.com/homepages/marcocantu'#13 +
'Email: marcocantu@compuserve.com',
mtInformation, [mbOK], 0);
end;
end.